/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import client.ClientView;
import java.sql.ResultSet;
import java.sql.SQLException;
import view.EditGSTView;
import view.EditPromotionView;
import view.PurchaseTicketView;

/**
 *
 * @author Tobias
 */
public class Sale {
    private static QueryModel query = null;
    private static ResultSet result = null;

    public Sale() {

    }

    public static void purchaseTicket(String flightID) {
        query = new QueryModel();
        //query.recordPurchase(flightID, user, flightPrice, gst);
        query.updateFlight(flightID);
    }

    public double calculatePrice() {
        double price = 0;


        return price;
    }

    public void setGST(String gst) {
        query = new QueryModel();
        query.editGST(gst);
    }

    public static double getGST() throws SQLException {
        double gst = 0;
        query = new QueryModel();
        result = query.getGST();

        while (result.next()) {
            gst = (result.getDouble(1));
        }
        return gst;
    }

    public static double getDiscount() throws SQLException {
        double discount = 0;
        query = new QueryModel();
        result = query.getDiscount();

        while (result.next()) {
            discount = (result.getDouble(1));
        }
        return discount;
    }

    public static int getPromoMin() throws SQLException {
        int min = 0;
        query = new QueryModel();
        result = query.getPromMin();

        while (result.next()) {
            min = (result.getInt(1));
        }
        return min;
    }

    public static double getAirportTax(String airportName) throws SQLException {
        double tax = 0;
        query = new QueryModel();
        result = query.getAirportTax(airportName);

        while (result.next()) {
            tax = (result.getDouble(1));
        }
        return tax;
    }
    
    public static void setPromotion(String discount, String tickets) {
        query = new QueryModel();
        query.editPromotion(discount, tickets);
    }

    public static void loadPurchaseTicketView() throws SQLException {
        ClientView view = ClientView.getInstance();
        PurchaseTicketView pt = new PurchaseTicketView(view);
        pt.pack();
        view.centerWindow(pt);
        pt.setVisible(true);
    }

    public static void loadGSTView() {
        ClientView view = ClientView.getInstance();
        EditGSTView ed = new EditGSTView(view);
        ed.pack();
        view.centerWindow(ed);
        ed.setVisible(true);
    }

    public static void loadPromotionView() {
        ClientView view = ClientView.getInstance();
        EditPromotionView pv = new EditPromotionView(view);
        pv.pack();
        view.centerWindow(pv);
        pv.setVisible(true);
    }

}
